home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
prog
/
pas_all.zip
/
TI179.ASC
< prev
next >
Wrap
Text File
|
1991-09-11
|
5KB
|
199 lines
PRODUCT : TURBO PASCAL NUMBER : 179
VERSION : 3.0xx
OS : ALL
DATE : May 21, 1986 PAGE : 1/3
TITLE : ALTERNATIVE FILE COPY ROUTINE
program FileCopy;
{
This is a simple file copy program that illustrates how to use
BlockRead and BlockWrite to make an exact copy of any file.
Note: If you want to adapt this program so that it will work
on the CP/M 80 or CP/M 86 versions of Turbo Pascal you
must do the following:
(1) Change the variables "SizeInBytes" and "LastByte" from real
variables to integer variables.
(2) Change calls to "LongFileSize" and "LongSeek" to "FileSize"
and "Seek."
(3) Take out the call to "Trunc(LastByte)" and change it to
just "LastByte."
}
const
BufSize = 128; { The buffer SizeInBlocks }
type
{ The type for the buffer variable }
BufType = array[1..BufSize] of byte;
var
Source, Dest : file; { The input and output files }
SourceName, { The input and output file names }
DestName : string[14];
Buffer : BufType; { The buffer for block transfers }
SizeInBytes, { The size in bytes of source file }
LastByte : real; { The position of the last byte in }
{ the last partially full buffer }
{ read from the source file. }
SizeInBlocks, { The size in blocks of the source }
{ file }
Count : integer; { A general use counter variable }
PRODUCT : TURBO PASCAL NUMBER : 179
VERSION : 3.0xx
OS : ALL
DATE : May 21, 1986 PAGE : 2/3
TITLE : ALTERNATIVE FILE COPY ROUTINE
FileExists : boolean; { Flag to test if source file exits }
ByteFile : file of byte; { Used for byte transfers }
begin { FileCopy }
Write('Copy from: ');
Readln(SourceName);
{ Calculate the size in bytes of }
{ the source file }
Assign(ByteFile, SourceName);
{$I-} Reset(ByteFile); {$I+}
FileExists := (IOResult = 0);
SizeInBytes := LongFileSize(ByteFile);
Close(ByteFile);
if FileExists then
begin
{ Open the source file as an }
{ untyped file }
Assign(Source, SourceName);
{$I-} Reset(Source); {$I+}
FileExists := (IOResult = 0);
{ Calculate the size of the }
{ source file in blocks }
SizeInBlocks := FileSize(Source);
{ Calculate the position of the }
{ last byte in the last partially }
{ full buffer read with BlockRead }
LastByte := SizeInBytes -
((SizeInBlocks-1) * 128.0);
end;
if FileExists then
begin
{ Open the destination file }
Write(' To: ');
Readln(DestName);
Assign(Dest, DestName);
Rewrite(Dest);
{ Copy all the full buffers to }
PRODUCT : TURBO PASCAL NUMBER : 179
VERSION : 3.0xx
OS : ALL
DATE : May 21, 1986 PAGE : 3/3
TITLE : ALTERNATIVE FILE COPY ROUTINE
{ the destination file }
for Count := 1 to SizeInBlocks-1 do
begin
BlockRead(Source, Buffer, 1);
BlockWrite(Dest, Buffer, 1);
end;
{ Read the last partially full }
{ buffer }
BlockRead(Source, Buffer, 1);
{ Close up the open files }
Close(Source);
Close(Dest);
{ Open the destination file as a }
{ file of byte and seek to the end }
Assign(ByteFile, DestName);
Reset(ByteFile);
LongSeek(ByteFile, LongFileSize(ByteFile));
{ Append the partially full buffer }
{ to the end of the destination }
{ file and then close it }
for Count := 1 to Trunc(LastByte) do
Write(ByteFile, Buffer[Count]);
Close(ByteFile);
end
else
{ Issue an error message if an }
{ error occured on the reset }
Writeln('An error occurred when resetting "', SourceName, '".');
end. { FileCopy }